package com.example.sql_damo;


import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class findpassword extends AppCompatActivity {
    SQLiteDatabase database;

    DBhelpen dBhelpen;
    private EditText name;
    private EditText email;
    private Button ok;
    private String names;
    private String emails;
    private String data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_findpassword);
        dBhelpen=new DBhelpen(this);

        ok =findViewById(R.id.find_ok);
        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                name =findViewById(R.id.find_userss);
                email =findViewById(R.id.find_emailss);

                names =name.getText().toString().trim();
                emails =email.getText().toString().trim();

                if (name_log(names,emails)){
                    Intent intent=new Intent(findpassword.this,modification.class);
                    intent.putExtra("name",names);
                    startActivity(intent);
                }else {
                    Toast.makeText(findpassword.this, "cw"+data, Toast.LENGTH_SHORT).show();
                }

            }
        });

    }






    private boolean name_log(String names,String emails) {


        database = dBhelpen.getReadableDatabase();
        Cursor cursor = database.query("INFOMATION",null,"NAME=? AND EMAIL=?",new String[]{names+"",emails+""},null,null,null);
        Toast.makeText(this, "aaaaaa"+data, Toast.LENGTH_SHORT).show();

        if (cursor.moveToFirst()){
            data=cursor.getString(1);
            cursor.close();
            return true;
        }
        return false;
    }

}
